﻿using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Nucleo.Windows.Elements;


namespace EventMonitor.Windows
{
	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class HealthMonitoringWindow : Window
	{
		#region " Constructors "

		public HealthMonitoringWindow()
		{
			this.InitializeComponent();
		}

		#endregion



		#region " Event Handlers "

		private void DatabaseSelector_Cancelled(object sender, EventArgs e)
		{
			this.SelectDatabasePopup.IsOpen = false;
			this.SelectDatabasePopup.StaysOpen = false;
		}

		private void DatabaseSelector_Submitted(object sender, EventArgs e)
		{
			DataTable webEvents = null;

			try
			{
				using (DbDataAdapter adapter = new SqlDataAdapter("select * from aspnet_WebEvent_Events", this.DatabaseSelector.ConnectionString))
				{
					webEvents = new DataTable();
					adapter.Fill(webEvents);

					this.WebEventItems.ItemsSource = webEvents.DefaultView;
				}

				this.SelectDatabasePopup.IsOpen = false;
				this.SelectDatabasePopup.StaysOpen = false;
			}
			catch (Exception ex)
			{
				MessageBox.Show("There was a problem connecting to the database: " + ex.Message);
			}
		}

		private void SelectDatabaseButton_Click(object sender, RoutedEventArgs e)
		{
			this.SelectDatabasePopup.IsOpen = true;
			this.SelectDatabasePopup.StaysOpen = true;
		}

		#endregion
	}
}
